﻿using System.Collections.Generic;
using System.Windows.Automation;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using QuickUIT.Controls;

namespace QuickUIT.Tests
{
    [TestClass]
    public class UITabTests
    {
        private BaseState _baseState;

        [TestInitialize]
        public void TestSetup()
        {
            _baseState = new BaseState(TestUtilities.GetTestApplicationFileName(), "@Name='QuickUIT Test Application'");
            _baseState.Execute();
        }

        [TestMethod]
        public void ShouldGetSelection()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UITab tabControl = window.UITab("@AutomationId='tabControl1'");
            AutomationElement[] selection = tabControl.GetSelection();
            Assert.AreEqual(1, selection.Length);
        }

        [TestMethod]
        public void ShouldGetCanSelectMultiple()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UITab tabControl = window.UITab("@AutomationId='tabControl1'");
            Assert.IsFalse(tabControl.CanSelectMultiple);
        }

        [TestMethod]
        public void ShouldGetIsSelectionRequired()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UITab tabControl = window.UITab("@AutomationId='tabControl1'");
            Assert.IsTrue(tabControl.IsSelectionRequired);
        }

        [TestMethod]
        public void ShouldGetHorizontallyScrollable()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UITab tabControl = window.UITab("@AutomationId='tabControl1'");
            Assert.IsFalse(tabControl.HorizontallyScrollable);
        }

        [TestMethod]
        public void ShouldGetVerticallyScrollable()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UITab tabControl = window.UITab("@AutomationId='tabControl1'");
            Assert.IsFalse(tabControl.VerticallyScrollable);
        }
 
        [TestMethod]
        public void ShouldSelectTabItemByName()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            UITab tabControl = window.UITab("@AutomationId='tabControl1'");
            AutomationElement[] selection = tabControl.GetSelection();
            Assert.AreEqual(1, selection.Length);
            Assert.AreEqual("Tab 1", selection[0].Current.Name);
            tabControl.SelectTab("Tab 2");
            selection = tabControl.GetSelection();
            Assert.AreEqual(1, selection.Length);
            Assert.AreEqual("Tab 2", selection[0].Current.Name);
        }

        [TestMethod]
        public void ShouldGetAllTabs()
        {
            var window = new UIWindow("@Name='QuickUIT Test Application'");
            List<UITab> tabs = window.UITabs();
            Assert.AreEqual(1, tabs.Count);
            Assert.AreEqual("tabControl1", tabs[0].AutomationId);
        }

        [TestCleanup]
        public void TestTeardown()
        {
            _baseState.Cleanup();
        }
    }
}